package com.karst.essentials.chapter04
{
	import flash.display.BitmapData;
	import flash.display.Shape;
	import flash.events.Event;
	
	import org.papervision3d.materials.BitmapMaterial;
	import org.papervision3d.objects.primitives.Plane;
	import org.papervision3d.view.BasicView;

	internal class BitmapMaterialShapeExampl extends BasicView
	{
		public function BitmapMaterialShapeExampl()
		{
			createView() ;
			startRendering() ;
		}
		
		private var circle : Shape = null ;
		private var bmpData : BitmapData = null ;
		private var material : BitmapMaterial = null ;
		private var plane : Plane = null ;
		private function createView() : void
		{
			if( circle == null )
			{
				circle = new Shape() ;
				circle.graphics.beginFill( 0x00FF00 ) ;
				circle.graphics.drawCircle( 0,0, 200 ) ;
				circle.graphics.endFill() ;
			}
			if( bmpData == null )
			{
				bmpData = new BitmapData( 200, 300, true, 0x00FF00 ) ;
				bmpData.draw( circle ) ;
			}
			if( material == null )
			{
				material = new BitmapMaterial( bmpData, false ) ;
				material.doubleSided = true ;
				material.smooth = true ;
			}
			if( plane == null )
				plane = new Plane( material, 300, 400, 12, 10 ) ;
			
			scene.addChild( plane ) ;
		}
		
		override protected function onRenderTick(event:Event=null):void
		{
			super.onRenderTick( event ) ;
			if( plane )
				plane.localRotationY++ ;
		}
	}
}